const Router = require('koa-router')
const router = new Router({ prefix: '/user' })
const {
    userValidator,
    verifyUser,
    cryptPassword,
    verifyLogin
} = require('../middleware/user.middleware')
const {
    auth
} = require('../middleware/auth.middleware')
const { userRegister, userLogin, changePassword } = require('../controller/user.controller')

router.get('/', (crt, next) => {
    crt.body = '获取用户列表'
})

// 注册接口
router.post('/register', userValidator, verifyUser, cryptPassword, userRegister)

// 登录接口
router.post('/login', userValidator, verifyLogin, userLogin)

// 修改密码接口
router.patch('/', auth, cryptPassword, changePassword)

module.exports = router